﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BiliBiliCSharpStudy.old {
    /**
     * 类型转换 (int)a
     */
    class TypeConversionDemo {
        public static void demo() {
            //test1();
            //test2();
            //test3();
            //test4();
            test5();
        }

        public static void test5() {
            Stone stone = new Stone();
            stone.Age = 5000;
            Monkey wukongSun = (Monkey)stone;
            Console.WriteLine(wukongSun.Age);
        }

        public static void test4() {
            Console.WriteLine(ushort.MaxValue);
            uint x = 65536;
            ushort y = (ushort)x;
            Console.WriteLine(y);
        }

        //polymorphism(多态)
        public static void test3() {
            Teacher t = new Teacher();
            Human h = t; //隐式类型转换
            Animal a = h; //隐式类型转换
            a.Eat();
        }

        public static void test2() {
            int x = int.MaxValue;
            long y = x; // 隐式类型转换
            Console.WriteLine(y);
        }

        public static void test1() {
            string str1 = Console.ReadLine();
            string str2 = Console.ReadLine();
            int x = Convert.ToInt32(str1);
            int y = Convert.ToInt32(str2);
            Console.WriteLine(x + y);
        }
    }

    class Animal {
        public void Eat() {
            Console.WriteLine("Eating...");
        }
    }
    class Human : Animal {
        public void Think() {
            Console.WriteLine("Who I am?");
        }
    }
    class Teacher : Human {
        public void Teach() {
            Console.WriteLine("I teach programming.");
        }
    }

    // 类型转换的秘密
    class Stone {
        public int Age;

        // 将石头转换为猴子
        // explicit -> implicit , 就变成了隐式转换
        public static explicit operator Monkey(Stone stone) {
            Monkey m = new Monkey();
            m.Age = stone.Age / 500;
            return m;
        }
    }
    class Monkey {
        public int Age;
    }
}
